/**
 *    Copyright 2009-2015 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.apache.ibatis.plugin;

import java.util.Properties;

/**
 * 拦截器
 *
 * Executor (update, query, flushStatements, commit, rollback, getTransaction, close, isClosed) 拦截执行器的方法
 * ParameterHandler (getParameterObject, setParameters) 拦截参数的处理
 * ResultSetHandler (handleResultSets, handleOutputParameters)拦截结果集的处理
 * StatementHandler (prepare, parameterize, batch, update, query) 拦截Sql语法构建的处理
 *
 *
 * xml配置
 * <plugins>
 *     <plugin interceptor="org.format.mybatis.cache.interceptor.ExamplePlugin"></plugin>
 * </plugins>
 *
 * @author Clinton Begin
 */
public interface Interceptor {

  /**
   *
   *实现拦截逻辑的地方
   * @param invocation
   * @return
   * @throws Throwable
   */
  Object intercept(Invocation invocation) throws Throwable;

  /**
   *是否触发intercept()
   * 当前这个拦截器生成对目标target的代理，实际是通过Plugin.wrap(target,this)来完成的，把目标target和拦截器this传给了包装函数。
   * @param target
   * @return
   */
  Object plugin(Object target);

  /**
   * 用于设置额外的参数，参数配置在拦截器的Properties节点里。
   * @param properties
   */
  void setProperties(Properties properties);

}
